/**
 *  @author yinghui.zhang  用户角色授权
 */
 
Ext.ns("cn.christ.web.action.dict.person");
var userRoleForm = cn.christ.web.action.dict.person.UserRoleForm; 

userRoleForm = function() {
	var   rolestore, rolegrid, secondGridStore, secondGrid, rolewin;
	var cols = [
			    new Ext.grid.RowNumberer(),
				{ id : 'name', header: "角色名称", width: 160, sortable: true, dataIndex: 'roleName'}
			];
	return {
		
		createRoleStore : function(){
			rolestore =  new Ext.data.Store( {
							proxy : new Ext.data.HttpProxy( { url :  cfg.cxt+'/role/list.action' }),
							reader : new Ext.data.JsonReader({
								totalProperty : 'results',
								root : 'list',
								idProperty:'id'
							}, ["id","roleName"] ),
							listeners : { 
								loadexception : bangni.storeLoadError
							},
							paramNames : { start : 'page.start',limit : 'page.limit',sort : 'page.sort',dir : 'page.dir' }
					});
			return rolestore;
		},
		
		createRolegrid : function(){
			rolegrid =  new Ext.grid.GridPanel(
						  {
								    autoScroll : true,
									store : rolestore,
									enableDragDrop   : true,
									ddGroup          : 'secondGridDDGroup',
									loadMask : { msg : '正在加载表格数据,请稍等...' },
									stripeRows : true,
									autoExpandColumn : 'roleName',
									sm : new Ext.grid.RowSelectionModel({singleSelect : true }),
									columns : [
									        new Ext.grid.RowNumberer(),
										    {id :'roleName',sortable : true,dataIndex : "roleName",header : "角色名称"}],
									viewConfig : { forceFit : true },
									tbar:[
									  {
										 xtype : "label",
									     html:'<font color="blue">所有角色（添加，请拖拽匹配角色到右侧）</font>'
									  }
									],
									bbar : {
										id : 'rolepage',
										xtype : 'pageinfobar',
										pageSize : 20,
										store : rolestore,
										pageMethod : personView.queryRoleItem
									}
						});
			return rolegrid;
		
		},
		
		createSecondGridStore : function() {
			secondGridStore =  new Ext.data.Store( {
								proxy : new Ext.data.HttpProxy( { url :  cfg.cxt+'/user/list.action' }),
								reader : new Ext.data.JsonReader({
									totalProperty : 'results',
									root : 'list',
									idProperty:'id'
								}, ["id","roleName"] ),
								listeners : { 
									loadexception : bangni.storeLoadError
								},
								paramNames : { start : 'page.start',limit : 'page.limit',sort : 'page.sort',dir : 'page.dir' }
					});
			return secondGridStore;
		},
		
		createSecondGrid : function() {
			secondGrid = new Ext.grid.GridPanel({
						    ddGroup          : 'firstGridDDGroup',
					        store            : secondGridStore,
					        columns          : cols,
						    enableDragDrop   : true,
					        stripeRows       : true,
					        autoExpandColumn : 'name',
							tbar:[
								   {
									 xtype : "label",
								     html:'<font color="blue">已选角色（删除，请拖拽所选角色到左侧）</font>'
								  }
								]
				    });
			return secondGrid;
		},
		
		createRoleWindow : function() {
			rolewin =   new ExtWin({
						layout : 'hbox',
						width : 650,
						height : 400,
						defaults     : { flex : 1 }, //auto stretch
						layoutConfig : { align : 'stretch' },
						items        : [
							rolegrid,
							secondGrid
						]
					});	  
			return rolewin;
		
		}
	}
}();

